<script src="/include/calendar/calendar.js"></script>
<link href="/include/bootstrapadmin/css/morris.css" rel="stylesheet">
<div class="pageheader">
	<h2>
		<i class="fa fa-bar-chart-o"></i>统计管理
	</h2>
	<div class="breadcrumb-wrapper">
		<span class="label">你所在的位置：</span>
		<ol class="breadcrumb">
			<li><a href="/index">ERP管理系统</a></li>
			<li>销售管理</li>
			<li class="active">每日销售量统计</li>
		</ol>
	</div>
</div>
<div class="contentpanel">
	<div class="main">
		<form id="statisticsForm" class="form-inline" method="post" style="margin-bottom: 10px;">
			<div class="form-group">
				<label for="date">日期:</label> 
				<input class="form-control" type="text" name="starttime" onclick="new Calendar().show(this);" readonly="readonly" value="<?php echo $this->starttime;?>"> 
			</div>
			<div class="form-group">
				<label for="Site">网站:</label> 
				<select name="site" class="form-control">
					<option value="">请选择</option>
					<?php
					foreach ( $this->siteArr as $sitev ) {
						if ($this->site == $sitev) {
							echo '<option value="' . $sitev . '" selected="selected">' . $sitev . '</option>';
						} else {
							echo '<option value="' . $sitev . '">' . $sitev . '</option>';
						}
					}
					?>
	            </select>
			</div>
			<button type="submit" class="btn btn-primary">搜索</button>
		</form>
	</div>
	<?php if(empty($this->site)){?>
	<div class="table-responsive">
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th>类型</th>
                    <th>gogoalshop</th>
                    <th>minejerseys</th>
                    <th>jerseysmark</th>
                    <th>goaljerseys</th>
                    <th>fancybestdeal</th>
                    <th>elmontyouthsoccer</th>
                    <th>bestcheapsoccer</th>
                </tr>
            </thead>
            <tbody>      
                <?php foreach ($this->sum as $typek=>$typev){?>
                <tr>
                    <td><?php if($typek=='money'){echo '总额/美元';}elseif($typek=='order'){echo '订单/个';}elseif($typek=='piece'){echo '商品/件';} ?></td>
                    <td><?php echo empty($typev['gogoalshop'])?0:$typev['gogoalshop']; ?></td>
                    <td><?php echo empty($typev['minejerseys'])?0:$typev['minejerseys']; ?></td>
                    <td><?php echo empty($typev['jerseysmark'])?0:$typev['jerseysmark']; ?></td>
                    <td><?php echo empty($typev['goaljerseys'])?0:$typev['goaljerseys']; ?></td>
                    <td><?php echo empty($typev['fancybestdeal'])?0:$typev['fancybestdeal']; ?></td>
                    <td><?php echo empty($typev['elmontyouthsoccer'])?0:$typev['elmontyouthsoccer']; ?></td>
                    <td><?php echo empty($typev['bestcheapsoccer'])?0:$typev['bestcheapsoccer']; ?></td>
                </tr>
                <?php }?>
                <tr>
                    <td>客单价</td>
                    <td><?php echo round($this->sum['money']['gogoalshop']/$this->sum['order']['gogoalshop'],2); ?></td>
                    <td><?php echo round($this->sum['money']['minejerseys']/$this->sum['order']['minejerseys'],2); ?></td>
                    <td><?php echo round($this->sum['money']['jerseysmark']/$this->sum['order']['jerseysmark'],2); ?></td>
                    <td><?php echo round($this->sum['money']['goaljerseys']/$this->sum['order']['goaljerseys'],2); ?></td>
                    <td><?php echo round($this->sum['money']['fancybestdeal']/$this->sum['order']['fancybestdeal'],2); ?></td>
                    <td><?php echo round($this->sum['money']['elmontyouthsoccer']/$this->sum['order']['elmontyouthsoccer'],2); ?></td>
                    <td><?php echo round($this->sum['money']['bestcheapsoccer']/$this->sum['order']['bestcheapsoccer'],2); ?></td>
                </tr>
		    </tbody>
        </table>
    </div>
    <?php } ?>
	<?php 
	if(!empty($this->site)){
	?>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h4 class="panel-title">24小时成交统计图：<?php echo $this->site; ?></h4>
		</div>
		<div class="panel-body">
			<div class="row">
		    <?php foreach ($this->data[substr($this->site,0,-4)] as $type => $d){ ?>
				<div class="col-md-6 mb30">
					<h5 class="subtitle"><?php if($type=='money'){echo '成交额柱状图';}elseif($type=='order'){echo '成交订单柱状图';}elseif($type=='piece'){echo '成交商品数柱状图';}?></h5>
					<p>
					    <?php if($type=='money'){echo '共计成交额/美元：';}elseif($type=='order'){echo '共计订单/个：';}elseif($type=='piece'){echo '共计成交商品数/件：';}?>
					    <?php 
					    $s = 0;
					    foreach ($d as $dv){ 
					    	$s += $dv;
					    }
					    echo $s;
					    ?>
					</p>
					<div id="<?php echo substr($this->site,0,-4).'-'.$type; ?>" class="body-chart"></div>
				</div>
		    <?php } ?>
			</div>
		</div>
	</div>
	<?php }else{ ?>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h4 class="panel-title">
			<?php echo '合计：成交额$'.$this->total['money'].'；成交订单'.$this->total['order'].'个；成交商品数'.$this->total['piece'].'件'; ?>
			</h4>
		</div>
		<div class="panel-body">
			<div class="row">
			    <?php foreach ($this->sum as $k=>$v){ ?>
				<div class="col-md-6 mb30">
					<h5 class="subtitle mb5"><?php if($k=='money'){echo '成交额饼状图';}elseif($k=='order'){echo '成交订单饼状图';}elseif($k=='piece'){echo '成交商品数饼状图';}?></h5>
					<p class="mb15"></p>
					<div id="<?php if($k=='money'){echo 'piemoney';}elseif($k=='order'){echo 'pieorder';}elseif($k=='piece'){echo 'piepiece';}?>" style="width: 100%; height: 300px"></div>
				</div>
				<?php } ?>
			</div>
		</div>
	</div>
	<?php } ?>
</div>
<script src="/include/bootstrapadmin/js/flot/jquery.flot.min.js"></script>
<script src="/include/bootstrapadmin/js/flot/jquery.flot.resize.min.js"></script>
<script src="/include/bootstrapadmin/js/flot/jquery.flot.symbol.min.js"></script>
<script src="/include/bootstrapadmin/js/flot/jquery.flot.crosshair.min.js"></script>
<script src="/include/bootstrapadmin/js/flot/jquery.flot.categories.min.js"></script>
<script src="/include/bootstrapadmin/js/flot/jquery.flot.pie.min.js"></script>
<script src="/include/bootstrapadmin/js/morris.min.js"></script>
<script src="/include/bootstrapadmin/js/raphael-2.1.0.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
	
	"use strict";
    
    /***** PIE CHART *****/
	<?php 
	if(!empty($this->sum)){
		$colors = array('gogoalshop'=>'#428BCA','minejerseys'=>'#1CAF9A','jerseysmark'=>'#F0AD4E','goaljerseys'=>'#428BCA','fancybestdeal'=>'#5BC0DE','elmontyouthsoccer'=>'#F0AD4E','bestcheapsoccer'=>'#1CAF9A');	    
	    foreach ($this->sum as $type => $tv){
	?> 
    var piedata<?php echo $type; ?> = [
        <?php foreach ($tv as $site => $v){ ?>
        { label: "<?php echo $site; ?>", data: [[1,<?php echo $v; ?>]], color: '<?php echo $colors[$site]; ?>'},
        <?php }?>
	 ];
    jQuery.plot('#pie<?php echo $type; ?>', piedata<?php echo $type; ?>, {
        series: {
            pie: {
                show: true,
                radius: 1,
                label: {
                    show: true,
                    radius: 2/3,
                    formatter: labelFormatter,
                    threshold: 0.05
                }
            }
        },
        grid: {
            hoverable: true,
            clickable: true
        }
    });
    <?php  
        } 
    }
    ?>
    /***** PIE CHART *****/

    <?php 
    if(!empty($this->site)){
    	foreach ($this->data as $site => $v){
    		foreach ($v as $type => $d){
    ?>
    var <?php echo $site.$type; ?> = new Morris.Bar({
        element: '<?php echo $site.'-'.$type; ?>',
        data: [
            { y: '1', a: <?php echo empty($d[1])?0:$d[1]; ?> },
            { y: '2', a: <?php echo empty($d[2])?0:$d[2]; ?> },
            { y: '3', a: <?php echo empty($d[3])?0:$d[3]; ?> },
            { y: '4', a: <?php echo empty($d[4])?0:$d[4]; ?> },
            { y: '5', a: <?php echo empty($d[5])?0:$d[5]; ?> },
            { y: '6', a: <?php echo empty($d[6])?0:$d[6]; ?> },
            { y: '7', a: <?php echo empty($d[7])?0:$d[7]; ?> },
            { y: '8', a: <?php echo empty($d[8])?0:$d[8]; ?> },
            { y: '9', a: <?php echo empty($d[9])?0:$d[9]; ?> },
            { y: '10', a: <?php echo empty($d[10])?0:$d[10]; ?> },
            { y: '11', a: <?php echo empty($d[11])?0:$d[11]; ?> },
            { y: '12', a: <?php echo empty($d[12])?0:$d[12]; ?> },
            { y: '13', a: <?php echo empty($d[13])?0:$d[13]; ?> },
            { y: '14', a: <?php echo empty($d[14])?0:$d[14]; ?> },
            { y: '15', a: <?php echo empty($d[15])?0:$d[15]; ?> },
            { y: '16', a: <?php echo empty($d[16])?0:$d[16]; ?> },
            { y: '17', a: <?php echo empty($d[17])?0:$d[17]; ?> },
            { y: '18', a: <?php echo empty($d[18])?0:$d[18]; ?> },
            { y: '19', a: <?php echo empty($d[19])?0:$d[19]; ?> },
            { y: '20', a: <?php echo empty($d[20])?0:$d[20]; ?> },
            { y: '21', a: <?php echo empty($d[21])?0:$d[21]; ?> },
            { y: '22', a: <?php echo empty($d[22])?0:$d[22]; ?> },
            { y: '23', a: <?php echo empty($d[23])?0:$d[23]; ?> },
            { y: '24', a: <?php echo empty($d[24])?0:$d[24]; ?> }
        ],
        xkey: ['y'],
        ykeys: ['a' ],
        labels: ['<?php echo $type; ?>' ],
        barColors: ['#1CAF9A' ],
        fillOpacity: 0.8,
        smooth: false,
        stacked: true,
        hideHover: true
    });
    <?php }?>
    jQuery(window).resize(function() {
		delay(function() {
			<?php echo $site; ?>money.redraw();
			<?php echo $site; ?>order.redraw();
			<?php echo $site; ?>piece.redraw();
	    }, 200);
    }).trigger('resize');
    <?php } }?>
    
    function labelFormatter(label, series) {
		return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>" + label + "<br/>" + Math.round(series.percent) + "%</div>";
    }
});
					
</script>